<template>
  <div id="login_page" class="login">
    <div class="login_left">
        <img src="../assets/bgLeft.png" alt="" class="left_img">
    </div>
    <div class="login_right">
      <img src="../assets/logoNav-old.png" alt="" >
      <div class="login_text" >北城集团数字工地管理平台</div>
      <!-- 登陆表单 -->
      <el-form ref="logingref" :model="loginForm"  >
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" placeholder="请输入用户名" ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" placeholder="请输入密码" show-password @keyup.enter.native="loging"></el-input>
        </el-form-item>
        <el-button type="primary" @click="loging" class="login_btn">登 录</el-button>
      </el-form>
    </div>

    <div class="system">
      <p>云上龙城 | 广西飞熊科技有限公司提供技术支持</p>
    <p>联系电话：15278843400</p>
    </div>
  </div>

</template>

<script>
import base from "../api/base"
export default {
  data() {
    return {
      // 登录表单的数据绑定对象
      loginForm: {
        username: "",
        password: ""
      },
      // 表单验证规则
      logRules: {
        // 用户名验证
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 1, max: 64, message: "请输入用户名", trigger: "blur" }
        ],
        // 密码验证
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 16, message: "长度在 3 到 16个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    loging() {
      // 表单登录之前的预验证
      this.$refs.logingref.validate(valid => {
        if (!valid) return; //表单预验证,true成功，false失败
        this.$api.loginhome
          .loging(this.loginForm)
          .then(res => {
            if (res.success) {
              this.$message.success("登录成功")
              console.log(res)
              window.localStorage.setItem("token", res.token)
              window.localStorage.setItem("role", res.data.roleCode)
              if(res.data.flag) {
                window.localStorage.setItem("flag", res.data.flag)
                // this.$router.push("/index")
                window.location.href = `${base.spurl}/lv/index.html?fid=1015913377235822436&token=${res.token}&path=mainhome`
              } else {
                this.$router.push("/index")
              }
            } else {
              this.$message.error(res.message);
            }
            // 将token保存在sessionStorage里面  setItem存  getItem取
            // console.log(window.sessionStorage.getItem("token"))
            // 通过编程式导航跳转
          })
          .catch(() => {
            //   console.log(error)
          })
      })
    }
  }
};
</script>

<style lang="scss" scoped>
#login_page {
  height: 100vh;
  min-width: 600px;
  width: 100%;
  display: flex;
  background: linear-gradient(90deg,#5a40f6 0%, #5d44d3 56%);
}
.login_left {
  height: 100vh;
  width:56%;
  display: flex;
  justify-content: center;
  align-items: center;
  .left_img {
    width: 474px;
    height:485px;
  }
}
.login_right {
  height: 100vh;
  width:44%;
  background:#7b5ed0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  img{
    width: 100px;
  }
}
.login_text{
  font-size:32px;
  font-family:YouYuan;
  color:#fff;
  line-height:35px;
  letter-spacing:5px;
  margin: 30px 0;
}
.el-input{
  width:380px;
  height:48px;
  background:rgba(237,239,244,1);
  border-radius: 4px;
}
/deep/.el-input__inner{
  height:48px !important;
}
.el-form{
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}
.login_btn{
  width:380px;
  height:48px;
  background:rgba(89,126,247,1);
  font-size:28px;
  color:rgba(255,255,255,1); 
  letter-spacing:4px;
}
/deep/.el-button{
  font-weight: 400;
  padding: 0;
}
/deep/input::-ms-input-placeholder{
    text-align: center;
}
/deep/input::-webkit-input-placeholder{
    text-align: center;
}
.system{
  position: fixed;
  width: 100%;
  text-align: center;
  bottom: 20px;
  color: #D0D0D2;
}
</style>
